$(function () {
    $('#captcha-img').click(function (event) {
        var self = $(this);
        var src = self.attr('src');
        var newsrc = zlparam.setParam(src,'xx',Math.random());
        self.attr('src',newsrc);
    });
});

$(function () {
    $('#btn_sms_captcha').click(function (event) {
        event.preventDefault();
        var self = $(this);
        var telephone = $("input[name='telephone']").val();
        if(!(/^1[345879]\d{9}$/.test(telephone))){
            zlalert.alertInfoToast('请输入正确的手机号码！');
            return;
        }
        var timestamp = (new Date).getTime();
        var sign = md5(timestamp+telephone+"afjeaifjgjkdsd1456*&^%$");
        zlajax.post({
            'url':'/c/sms_captcha/',
            'data':{
                'telephone':telephone,
                'timestamp':timestamp,
                'sign':sign
            },
            'success':function (data){
                if(data['code']==200){
                    zlalert.alertSuccessToast('验证码发送成功');
                    self.attr('disabled','disabled');
                    var timeCount = 60;
                    var timer = setInterval(function () {
                        timeCount--;
                        self.text(timeCount);
                        if(timeCount <= 0){
                            self.removeAttr('disabled');
                            clearInterval(timer);
                            self.text('发送验证码')
                        }
                    },1000);
                }else{
                    zlalert.alertInfoToast(data['message']);
                }
            },
            'fail':function (error) {
                zlalert.alertInfoToast('验证码发送失败');
            }
        });

    });

});
        //加密压缩，JS混淆https://www.sojson.com
        //对提交数据的请求代码，要加缩压缩，提高安全

$(function () {
    $('#submit-btn').click(function (event) {
        event.preventDefault();
        var telephoneE = $("input[name='telephone']");
        var sms_captchaE = $("input[name='sms_captcha']");
        var usernameE = $("input[name='username']");
        var password1E = $("input[name='password1']");
        var password2E = $("input[name='password2']");
        var graph_captchaE = $("input[name='graph_captcha']");

        var telephone = telephoneE.val();
        var sms_captcha = sms_captchaE.val();
        var username = usernameE.val();
        var password1 = password1E.val();
        var password2 = password2E.val();
        var graph_captcha = graph_captchaE.val();

        zlajax.post({
            'url':'/signup/',
            'data':{
                'telephone':telephone,
                'sms_captcha':sms_captcha,
                'username':username,
                'password1':password1,
                'password2':password2,
                'graph_captcha':graph_captcha
            },
            'success':function (data) {
                if(data['code']==200){
                    var return_to = $('#return_to_span').text();
                    if(return_to){
                        window.location = return_to;
                    }else{
                        window.location = '/';
                    }

                }else{
                    zlalert.alertInfo(data['message']);
                }
                
            },
            'fail':function (error) {
                zlalert.alertNetworkError();
            }
        });
            
        
    });
});
